package dvx.mp.ivisual.desktop.ui.model;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;

public class GridImportInvoicesModel extends AbstractTableModel {
	/***/
	private static final long serialVersionUID = 1L;

	private final String[] headers;

	private List<IInvoice> invoices;

	public GridImportInvoicesModel()	{
		this.headers = new String[]{
				"Fecha", "RFC", "Concepto/Empresa", "Monto", "IVA", "Total", "Ingreso"};
	}

	public GridImportInvoicesModel(List<IInvoice> invoices)	{
		this();

		this.invoices = invoices;
	}

	public void setInvoices(List<IInvoice> invoices)	{
		if(null == this.invoices)	{
			this.invoices = new ArrayList<IInvoice>();
		}

		this.invoices = invoices;
	}

	public int getColumnCount() {
		return this.headers.length;
	}

	public int getRowCount() {
		return this.invoices.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		IInvoice invoice = this.invoices.get(rowIndex);

		switch (columnIndex) {
		case 0:
			return invoice.getDate();
		case 1:
			return invoice.getRFC();
		case 2:
			return invoice.getConcepto();
		case 3:
			return invoice.getMonto();
		case 4:
			return invoice.getIVA();
		case 5:
			return invoice.getTotal();
		case 6:
			return invoice.isIncome();
		default:
			throw new IllegalArgumentException("Column index [ " + " ] doesn't exists");
		}
	}

	@Override
	public String getColumnName(int index)	{
		return this.headers[index];
	}
	
	public Class<?> getColumnClass(int index)	{
		switch (index) {
		case 0:
			return Calendar.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return Double.class;
		case 4:
			return Double.class;
		case 5:
			return Double.class;
		case 6:
			return Boolean.class;
		default:
			throw new IllegalArgumentException("Column index [ " + " ] doesn't exists");
		}
	}
}
